package com.jumi.microservice.material.service.impl;

import com.jumi.microservice.common.exception.BaseException;
import com.jumi.microservice.common.exception.ExceptionEnum;
import com.jumi.microservice.common.exception.ExceptionSupply;
import com.jumi.microservice.material.domain.JmSupplier;
import com.jumi.microservice.material.dto.supplier.JmSupplierResponse;
import com.jumi.microservice.material.mapper.JmSupplierMapper;
import com.jumi.microservice.material.service.JmSupplierService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ssk
 * @create 2020/7/17 9:34
 **/
@Service
public class JmSupplierServiceImpl implements JmSupplierService {

    @Resource
    private JmSupplierMapper jmSupplierMapper;

    @Override
    public int save(JmSupplier jmSupplier) {
        int hasSame = jmSupplierMapper.findCount(jmSupplier);
        if (hasSame != 0) {
            throw new ExceptionSupply(500,"该供应商名称已经存在！").newException();
        } else {
            return jmSupplierMapper.save(jmSupplier);
        }
    }

    @Override
    public int update(JmSupplier jmSupplier) {
        int hasSame = jmSupplierMapper.findCount(jmSupplier);
        if (hasSame != 0) {
            throw new ExceptionSupply(500,"该供应商名称已经存在！").newException();
        } else {
            int getback = jmSupplierMapper.update(jmSupplier);
            return getback;
        }
    }

    @Override
    public JmSupplier findById(Long id) {
        JmSupplier listOne = jmSupplierMapper.findById(id);
        return listOne;
    }

    @Override
    public List<JmSupplier> findAll(JmSupplier jmSupplier) {
        List<JmSupplier> getBack = jmSupplierMapper.findAll(jmSupplier);
        return getBack;
    }


    @Override
    public int deleteById(JmSupplier jmSupplier) {
        int getBack = jmSupplierMapper.deleteById(jmSupplier);
        return getBack;
    }


    @Override
    public int deleteBatchByIds(Long[] ids) {
        return 0;
    }

    @Override
    public int statusById(JmSupplier jmSupplier) {
        int getBack = jmSupplierMapper.statusById(jmSupplier);
        return getBack;
    }

    @Override
    public List<JmSupplierResponse> findBySupplierIds(List<Long> supplierIds) {
        return jmSupplierMapper.findBySupplierIds(supplierIds);
    }
}
